﻿using HomagGroup.Base.UI;
using HomagChina.Nesting.Views;
using System.Collections.Generic;
using System.Windows;

namespace HomagChina.Nesting.Router
{
    public class RouterModel : NotifyPropertyChangedBase
    {
        public Dictionary<string, RouterItemDataModel> RouterDictionary;
        public MainWindowViewModel mainWindowViewModel { get; set; }

        public RouterModel(MainWindowViewModel baseViewModel, bool isInit)
        {
            mainWindowViewModel = baseViewModel;
            Application.Current.Properties["RouterMap"] = new Dictionary<string, RouterItemDataModel> {
                {"1", new HomeRoute(mainWindowViewModel,isInit).HomeRouteModel },
                {"2", new SettingsRoute(mainWindowViewModel,isInit).SettingsRouteModel},
                {"4", new ErrorMessageRoute(mainWindowViewModel,isInit).ErrorMessageRouteModel},
                {"6", new StatisticsRoute(mainWindowViewModel,isInit).StatisticsRouteModel},
                {"7", new TransHistoryRoute(mainWindowViewModel,isInit).TransHistoryRouteModel}
            };
            RouterDictionary = (Dictionary<string, RouterItemDataModel>)Application.Current.Properties["RouterMap"];
            foreach (var item in RouterDictionary)
            {
                item.Value.userControl.DataContext = item.Value.ViewModel;
            }
        }

        public RouterItemDataModel UpdateBindDataContext(RouterItemDataModel routerInfo)
        {
            RouterItemDataModel newItem = null;
            switch (routerInfo.ID)
            {
                case "1":
                    newItem = new HomeRoute(mainWindowViewModel, true).HomeRouteModel;
                    break;

                case "2":
                    newItem = new SettingsRoute(mainWindowViewModel, true).SettingsRouteModel;
                    break;

                case "4":
                    newItem = new ErrorMessageRoute(mainWindowViewModel, true).ErrorMessageRouteModel;
                    break;

                case "6":
                    newItem = new StatisticsRoute(mainWindowViewModel, true).StatisticsRouteModel;
                    break;

                case "7":
                    newItem = new TransHistoryRoute(mainWindowViewModel, true).TransHistoryRouteModel;
                    break;

                default:
                    break;
            }
            return routerInfo.keepalive ? null : newItem;
        }
    }
}